<div class="page user-painel">

    <div class="box-header">
        <h2 class="col-xs-12 box-title">Meu Histórico</h2>

    </div>

    <!-- Nav tabs -->
    <ul class="nav nav-tabs">
        <li class="active"><a href="#lances" data-toggle="tab"><?php echo lang_system('user_tab_bids'); ?></a></li>
        <li><a href="#lancesArrematados" data-toggle="tab"><?php echo lang_system('user_tab_lotes_shop'); ?></a></li>
        <li><a href="#habilitação" data-toggle="tab"><?php echo lang_system('user_tab_enabling'); ?></a></li>

    </ul>

    <!-- Tab panes -->
    <div class="tab-content">
        <div class="tab-pane active" id="lances">
            <br/>
            <div class="box-lances">
                <table class="table table-bordered table-condensed table-responsive table-striped">   
                    <thead>
                        <tr class="info">
                            <th class="col-xs-1">Data</th>
                            <th class="col-xs-6">Descrição</th>
                            <th>Lote</th>
                            <th>Lance</th>
                            <th>Total</th>
                            <th>Total + Comissão</th>
                        </tr>
                    </thead>
                    <tbody>
                        <?php
                        $lances_add = array();
                        foreach ($lances as $lance):
                            if (!in_array($lance->LOTE_ID, $lances_add)):
                                // $lances_add[] = $lance->LOTE_ID;
                                ?>
                                <tr>
                                    <td><?php echo auto_format_data($lance->CRIADO, '-', '/'); ?></td>
                                    <td><?php echo $lance->DESCRICAO; ?></td>
                                    <td><?php echo str_num_lote_pad($lance->NUM_LOTE); ?></td>
                                    <td><?php echo number_format($lance->VALOR, 2, ',', '.'); ?></td>
                                    <td><?php echo number_format($lance->TOTAL, 2, ',', '.'); ?></td>
                                    <td><?php echo number_format($lance->TOTAL_COMISSAO, 2, ',', '.'); ?></td>
                                </tr>

                                <?php
                            endif;


                        endforeach;
                        ?>
                    </tbody>
                </table>

            </div>
        </div>
        <div class="tab-pane" id="lancesArrematados">
            <br/>
            <div class="box-lances">
                <?php
                if (isset($lances_arrematados)):


                    $group_by_leilao = array();
                    $this->table->set_template(array('table_open' => '<table class="table table-bordered table-condensed group-table" >'));
                    $this->table->set_heading('Data / Hora','Leilão','N. Lote', 'Lote', 'Valor', 'Comissao', 'Subtotal', '#');
                   
                    foreach ($lances_arrematados as $key=>$lca):
                        $row = array();
                        $row[] = array('data' => auto_format_data($lca->DATAHORA, '-', '/'),
                            'class' => 'col-xs-1');
                        
                        $row[] = array('data' => $lca->LEILAO_ID.'-'.$lca->TITLE,
                            'class' => 'col-xs-2');
                        $row[] = array('data' => str_num_lote_pad($lca->NUM_LOTE),
                            'class' => 'col-mini');
                        $row[] = array('data' => '(R'.  str_num_lote_pad($lca->LOTE_ID).') - '.$lca->DESCRICAO,
                            'class' => 'col-xs-4');
                        $row[] = array('data' => number_format($lca->TOTAL, '2', ',', '.') . '(BRL)',
                            'class' => 'col-xs-1');
                        $row[] = array('data' => number_format($lca->COMISSAO, '2', ',', '.') . '(BRL)',
                            'class' => 'col-xs-1');
                        $row[] = array('data' => number_format($lca->TOTAL_COMISSAO, '2', ',', '.') . '(BRL)',
                            'class' => 'col-xs-1');
                        $has_pgto = '<a  title="'.  lang_system('user_action_payment').'" class="icones-user" '
                                . 'href="' . site_url(BASE_URL_USER . '/pagamentos-' . $lca->LOTE_ID . '-' . $lca->LEILAO_ID . '.html') . '"><i class="fa fa-barcode"></i></a>';


                        if ($lca->CONDICIONAL == 'S' && $lca->VENDIDO == 'N') {
                            $has_pgto = '<span add="tooltip" title="'.  lang_system('user_title_lote_is_conditional').'" class="icones-user red"><i class="fa fa-exclamation-triangle"></i><span>';
                        }
                        
                        if($lca->APROUVE != NULL && $lca->APROUVE == 0){
                            $has_pgto = '<a href="#" '
                                    . ''
                                    . 'title="'.  lang_system('user_exist_proposta').'" class="icones-user" '
                                    . 'data-trigger-fancybox data-url="'.site_url('load-proposta-'.$lca->PROPOSTA_ID.'.html').'"><i class="fa fa-reply"></i></a>';
                        }
                       
                        if ($lca->PAGAMENTO_ID > 0) {
                            $has_pgto = '<a click-show-boleto href="#" '
                                    . ''
                                    . 'title="'.  lang_system('user_show_bolet').'" class="icones-user" '
                                    . 'data-url="' . site_url('boleto-' . $lca->HASH_BOLETO . '_ajax') . '" ><i class="fa fa-print"></i></a>';
                            
                            if($lca->PAGAMENTO_ENVIADO == 'N'){
                                $has_pgto .= ' | <a click-send-comprovante href="#"  class="icones-user" '
                                    . ' data-url="' . site_url('comprovante-' . $lca->HASH_BOLETO . '.html') . '" ><i class="fa fa-upload"></i></a>';
                            }
                            
                            if($lca->PAGAMENTO_ENVIADO == 'S' && $lca->CONFIRMADO == 'N'){
                                $has_pgto = '<span title="'.  lang_system('user_confirm_payment_off').'" add="tooltip" class="icones-user red"><i class="fa fa-circle"></i><span>';
                            }
                            if($lca->PAGAMENTO_ENVIADO == 'S' && $lca->CONFIRMADO == 'S' && $lca->NFE_LIBERADO == 'N'){
                                $has_pgto = '<span title="'.  lang_system('user_confirmed_payment').'" add="tooltip" class="icones-user"><i class="fa fa-check"></i><span>';
                            }
                            
                            if($lca->NFE_LIBERADO == 'S'){
                                $has_pgto = '<a data-type="iframe" href="'.site_url('load-nfe-'.$lca->PAGAMENTO_ID.'.html').'" target="_blank" data-url="" title="'.  lang_system('user_nfe_enabled').'" add="tooltip" class="icones-user"><i class="fa fa-file-pdf-o"></i><a>';
                            }
                            
                            
                        }
                        
                         if($lca->APROUVE != NULL && $lca->APROUVE == 2){
                            $has_pgto = '<span><i class="fa fa-times"></i></span>';
                        }
                        $row[] = array('data' => '<div class="btn-group-sm">' . $has_pgto . '</div>',
                            'class' => 'col-mini');
                        
                        $this->table->add_row($row);
                        //$rows[] = $row;
                    endforeach;
                   // echo '<pre>';
                   // print_r($rows);
                   echo $this->table->generate();
                   // echo '</pre>';      
                /*
                  $this->table->set_template(array('table_open'=>'<table class="table table-bordered table-condensed group-table" >'));
                  $i = 0;

                  foreach ($group_by_leilao as $key => $lrow) {

                  $total_lotes = 0;
                  $total_taxas = 0;
                  $toal_taxas_admin = 0;
                  $total_comissao = 0;
                  $total_lances = 0;
                  $desconto = 0;

                  $this->table->add_row(array('data'=>'Leilão - ' .$lrow->codigo .' | '.$lrow->razao .' | '.
                  'CNPJ - ' .format_cnpj_cpf($lrow->cnpj) . anchor('javascript:void(0);','[ - ] Detalhes','role="detailsUserLeilao" class="link pull-right" data-id="'.$lrow->codigo.'"')
                  ,'class'=>'group-by-lote' ,'colspan'=>6));
                  $this->table->add_row(
                  array('data'=>'Nº do Lote ','class'=>'group-by-lote lote-header line-'.$lrow->codigo),
                  array('data'=>'Descrição','class'=>'group-by-lote lote-header line-'.$lrow->codigo),
                  array('data'=>'Lance','class'=>'group-by-lote lote-header line-'.$lrow->codigo),
                  array('data'=>'Comissão ','class'=>'group-by-lote lote-header line-'.$lrow->codigo),
                  array('data'=>'Taxa Adm.','class'=>'group-by-lote lote-header line-'.$lrow->codigo),
                  array('data'=>'Total','class'=>'group-by-lote lote-header line-'.$lrow->codigo)
                  );
                  $join_lotes = array();
                  foreach ($lrow->lotes_arrematados as $ikey => $row) {

                  $lance = $row->TOTAL;
                  $comissao   = ($row->TOTAL * $row->comissao) / 100;
                  $taxa       = get_taxa($row->TOTAL);
                  $total      = $lance + $comissao + $taxa ;

                  $total_lances +=$lance;
                  $total_comissao +=$comissao;
                  $total_taxas   += $taxa;
                  $total_lotes += $total;

                  $this->table->add_row(
                  array('data'=>$row->num_lote,'style'=>'width:90px;' ,'class'=>'lote-header line-'.$lrow->codigo),
                  array('data'=>$row->titulo ,'class'=>'lote-header line-'.$lrow->codigo),
                  array('data'=> number_format($lance,2,',','.').' (BRL)' ,'class'=>'lote-header line-'.$lrow->codigo ),
                  array('data'=> number_format($comissao,2,',','.').' (BRL)' ,'class'=>'lote-header line-'.$lrow->codigo ),
                  array('data'=> number_format($taxa,2,',','.').' (BRL)' ,'class'=>'lote-header line-'.$lrow->codigo ),
                  array('data'=> number_format($total,2,',','.').' (BRL)' ,'class'=>'lote-header line-'.$lrow->codigo )
                  );

                  $join_lotes[]= $row->LOTE_ID;
                  }
                  $nfe_generate = $this->db->get_where('nfes',array('KEY_LOTES'=>implode('|',$join_lotes)));

                  $ac_nfe = '<span add="tooltip" class="pull-right" title="Aguardando liberação da nota"> '.add_image('icon-pdf-trans.png').'</span>';
                  $nfe_info = $nfe_generate->row();
                  if($nfe_generate->num_rows() > 0){

                  $ac_nfe = anchor(site_url(BASE_URL_USER.'/generateNFE/'.$lrow->user.'/'.$lrow->codigo),add_image('icon-pdf.png'),'class="pull-right" target="_blank" title="Prévia da Nota de Venda"');

                  }
                  $ac_payments = anchor(site_url('payments/lances/'.$lrow->user.'/'.$lrow->codigo),'<i class="glyphicon glyphicon-usd"></i> Pagar','class="btn-payment-confirm btn btn-xs btn-danger" title="Confirmar Pagamento"  message="Deseja confirmar o pagamento ?" role="confirm-buyer"');


                  $payment_confirm = $this->db->get_where('lances_pagamentos',array('KEY_LOTES'=>implode('|',$join_lotes),'USER_ID'=>$lrow->user));



                  // pagamento confirmado.    $row_payment =  $payment_confirm->row();
                  $row_payment = $payment_confirm->row();
                  if($payment_confirm->num_rows() > 0){
                  $ac_payments ='<span add="tooltip" title="Aguardando confirmação de pagamento" class=" btn btn-xs btn-warning"><i class="glyphicon glyphicon-usd"></i> Confirmado</span>';

                  if($row_payment->STATUS == 2){
                  $ac_payments ='<span add="tooltip" pcid="'.$row_payment->PAGAMENTO_ID.'" title="pagamento confirmado" class=" btn btn-xs btn-success"><i class="glyphicon glyphicon-usd"></i> Confirmado</span>';
                  }


                  }
                  if($row->CONDICIONAL == 'S'){
                  $ac_payments ='<span add="tooltip" title="Lote Condicional aguarde contato do comercial" class=" btn btn-xs btn-warning"><i class="glyphicon glyphicon-usd"></i> Condicional</span>';
                  }


                  $this->table->add_row(

                  array('data'=>'<strong></strong>','class'=>'group-by-lote','colspan'=>2),
                  array('data'=>' Total Lances ','class'=>'group-by-lote'),
                  array('data'=>' Total Comissões','class'=>'group-by-lote'),
                  array('data'=>' Total Taxas','class'=>'group-by-lote'),
                  array('data'=>' Total Leilão','class'=>'group-by-lote')
                  );

                  $this->table->add_row(

                  array('data'=>$ac_payments .$ac_nfe,'colspan'=>2,'style'=>'width:170px;'),
                  array('data'=>number_format($total_lances,2,',','.').' (BRL)' ),
                  array('data'=>number_format($total_comissao,2,',','.').' (BRL)'),
                  array('data'=>number_format($total_taxas,2,',','.').' (BRL)'),
                  array('data'=>number_format($total_lotes,2,',','.').' (BRL)')
                  );
                  $i+=1;

                  }

                  if(count($group_by_leilao) > 0){
                  echo  $this->table->generate();
                  }

                 */
                endif;
                ?>
                <!--
               </tbody>

           </table>
                -->
            </div>
        </div>
        <div class="tab-pane" id="habilitação"><br/>
            <table class="table table-bordered table-condensed">
                <thead>
                    <tr>
                        <th>Data</th>
                        <th>Leilão</th>
                        <th>Código</th>
                    </tr>
                </thead>
                <tbody>
                    <?php
                    if ($habilitacoes):
                        foreach ($habilitacoes as $habilitacao):
                            ?>
                            <tr>
                                <td><?php echo auto_format_data($habilitacao->CREATE, '-', '/'); ?></td>
                                <td><?php echo $habilitacao->NOME_FANTASIA; ?></td>
                                <td><span class="key-code-history"><?php echo $habilitacao->KEY_HASH; ?></span></td>


                            </tr>
                            <?php
                        endforeach;

                    endif;
                    ?>

                </tbody>

            </table></div>
        <div class="tab-pane" id="settings">...</div>
    </div>

</div>

<?php
add_js('plugins/frontend/jquery.Storage', 'footer', 3);
add_js('scripts/frontend/jquery.history', 'footer', 4);

add_js('plugins/frontend/jquery.mousewheel.min', 'footer', 11);
add_js('plugins/frontend/jquery.jqzoom-core', 'footer', 11);
add_js('plugins/frontend/fancybox/jquery.fancybox', 'footer', 6);
add_js('plugins/frontend/fancybox/jquery.fancybox-buttons', 'footer', 9);
add_js('plugins/frontend/fancybox/jquery.fancybox-media', 'footer', 9);
add_js('plugins/frontend/fancybox/jquery.fancybox-thumbs', 'footer', 9);
add_js('plugins/frontend/jquery.maskMoney', 'footer', 9);
add_js('scripts/user/jquery.pagamentos', 'footer', 9);
add_css('frontend/fancybox/jquery.fancybox', 'header', 13);
add_css('frontend/fancybox/helpers/jquery.fancybox-buttons', 'header', 14);
add_css('frontend/fancybox/helpers/jquery.fancybox-thumbs', 'header', 15);
add_css('frontend/jquery.jqzoom', 'footer', 16);
add_css('styles/animation', 'header', 5);
?>